package com.itheima.wisdomnext.controller;

import com.itheima.wisdomnext.entity.Ban;
import com.itheima.wisdomnext.entity.Result.ResponseResult;
import com.itheima.wisdomnext.service.BanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/api/ban")
public class BanController {

    @Autowired
    private BanService banService;

    /*
    // 用户封禁功能（暂未启用）
    @PostMapping("/banUser")
    public ResponseResult<Object> banUser(@RequestBody Ban ban) {
        boolean result = banService.banUser(ban);
        if (result) {
            return ResponseResult.success("用户封禁成功", null);
        } else {
            return ResponseResult.failure(400, "封禁失败");
        }
    }

    // 用户解禁功能（暂未启用）
    @PostMapping("/unbanUser")
    public ResponseResult<Object> unbanUser(@RequestBody Ban ban) {
        boolean result = banService.unbanUser(ban);
        if (result) {
            return ResponseResult.success("用户解禁成功", null);
        } else {
            return ResponseResult.failure(400, "解禁失败");
        }
    }
    */

    /**
     * 封禁帖子接口
     * @param ban 封禁信息对象，需包含 postId、操作人、封禁理由等
     * @return 操作结果
     */
    @PostMapping("/banPost")
    public ResponseResult<Object> banPost(@RequestBody Ban ban) {
        banService.banPost(ban);
        return ResponseResult.success("帖子封禁成功", null);
    }

    /**
     * 解禁帖子接口
     * @param ban 解禁对象，需包含 postId
     * @return 操作结果
     */
    @PostMapping("/unbanPost")
    public ResponseResult<Object> unbanPost(@RequestBody Ban ban) {
        banService.unbanPost(ban);
        return ResponseResult.success("帖子解禁成功", null);
    }

    /**
     * 封禁评论接口
     * @param ban 封禁信息，包含 commentId、操作人、理由等
     * @return 操作结果
     */
    @PostMapping("/banComment")
    public ResponseResult<Object> banComment(@RequestBody Ban ban) {
        banService.banComment(ban);
        return ResponseResult.success("评论封禁成功", null);
    }

    /**
     * 解禁评论接口
     * @param ban 解禁对象，需包含 commentId
     * @return 操作结果
     */
    @PostMapping("/unbanComment")
    public ResponseResult<Object> unbanComment(@RequestBody Ban ban) {
        banService.unbanComment(ban);
        return ResponseResult.success("评论解禁成功", null);
    }

    /**
     * 查询封禁记录接口，可通过 userId、postId 或 commentId 查询某项是否被封禁
     * @param userId 用户 ID（可选）
     * @param postId 帖子 ID（可选）
     * @param commentId 评论 ID（可选）
     * @return 封禁记录信息
     */
    @GetMapping("/checkBan")
    public ResponseResult<Ban> checkBan(@RequestParam(value = "userId", required = false) Integer userId,
                                        @RequestParam(value = "postId", required = false) Integer postId,
                                        @RequestParam(value = "commentId", required = false) Integer commentId) {
        Ban ban = banService.getBanInfo(userId, postId, commentId);
       return ResponseResult.success("查询成功", ban);
    }
}
